import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { getWeekMonthQuarterYear } from '/@/utils';
import { useMessage } from '/@/hooks/web/useMessage';
import { h } from 'vue';
import {JVxeTypes,JVxeColumn} from '/@/components/jeecg/JVxeTable/types'
const { createMessage } = useMessage();
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '信息分类',
    align:"center",
    dataIndex: 'category_dictText'
   },
   {
       title: '细分类型',
       align:"center",
       dataIndex: 'typeDesc'
      },
   {
    title: '标题',
    align:"center",
    dataIndex: 'titile'
   },
   {
    title: '摘要',
    align:"center",
    dataIndex: 'summary'
   },
   {
    title: '封面图',
    align:"center",
    dataIndex: 'coverImage',
      customRender:render.renderImage,
   },
   {
    title: '是否推荐',
    align:"center",
    dataIndex: 'priority_dictText',
   },
   
   
   {
    title: '发布状态',
    align:"center",
    dataIndex: 'publishStatus_dictText'
   },
   {
    title: '发布人',
    align:"center",
    dataIndex: 'publisher'
   },
   {
    title: '发布时间',
    align:"center",
    dataIndex: 'publishTime'
   },
   
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "信息分类",
      field: 'category',
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"web_school_message"
      },
      //colProps: {span: 6},
 	},
	{
      label: "标题",
      field: 'titile',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "发布状态",
      field: 'publishStatus',
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"web_publish_status"
      },
      //colProps: {span: 6},
 	},
  {
    label: '是否推荐',
    field: 'priority',
   component: 'JDictSelectTag',
   componentProps:{
       dictCode:"priority_type"
    },
  },
     {
      label: "发布时间",
      field: "publishTime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '信息分类',
    field: 'category',
    component: 'JDictSelectTag',
     componentProps: ({formModel}) => {
          return {
            dictCode: 'web_school_message',
            placeholder: '请选择信息分类',
            onChange(val){ 
              if (formModel.hasOwnProperty('type')) {
                formModel.type = '';
              } 
            },
            onDeselect(val){ 
              if (formModel.hasOwnProperty('type')) {
                formModel.type = '';
              } 
            },
          };
        }, 
        dynamicRules: ({model,schema}) => {
          return [ { required: true, message: '请选择信息分类!'}, ];
     },
     },
     {
         label: '细分类型',
         field: 'type',
         component: 'ApiSelect',
         componentProps: ({ formModel }) => {
         return {
             api: () => defHttp.get({ url: '/sys/dict/getDictItems/'+formModel.category }),
             resultField: 'result',
             labelField: 'label',
             valueField: 'value',
             params: {
                 code: formModel.category,//参数发生变化才会重新加载数据
             },
             immediate: false,
             onFocus: () => {
                 if (!formModel.category) {
                   createMessage.error(`请选择信息分类`);  
                 }
             }
         } 
        },
        dynamicRules: ({model,schema}) => {
         return [
                { required: true, message: '请选择细分类型!'},
         ];
         }
     },
     {
       label: '专业名称',
       field: 'majorName',
       component: 'Input',
       dynamicRules: ({model,schema}) => {
             return [
                    { required: true, message: '请输入专业名称!'},
             ];
        },
        show: ({ model }) => (model.category == 'sys_school_major'),
     },
      
  {
    label: '标题',
    field: 'titile',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入标题!'},
          ];
     },
       show: ({ model }) => (model.category != 'sys_image_type'),
  },
  {
    label: '摘要',
    field: 'summary',
    component: 'InputTextArea',
    show: ({ model }) => (model.category != 'sys_image_type'),
  },
  {
    label: '内容',
    field: 'content',
    component: 'JEditor',
    show: ({ model }) => (model.category != 'sys_image_type'),
  },
  
  {
    label: '发布状态',
    field: 'publishStatus',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"web_publish_status"
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请选择发布状态!'},
          ];
     },
  },
  {
    label: '是否悬浮窗',
    field: 'susWin',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"priority_type"
     },
       show: ({ model }) => (model.category == 'sys_school_news'),
  },
  {
    label: '悬浮窗图',
   field: 'img',
   component: 'JImageUpload',
    helpMessage: '建议尺寸：160px*160px',
   componentProps:{
      fileMax: 1
    },  
      show: ({ model }) => (model.susWin == '1'),
},
  {
    label: '是否推荐',
    field: 'priority',
   component: 'JDictSelectTag',
   componentProps:{
       dictCode:"priority_type"
    },
  	dynamicRules: ({model,schema}) => {
  	  return [
  	    { required: true, message: '请选择是否推荐!'},
  	  ];
  	},
    show: ({ model }) => (model.category != 'sys_party' && model.type != '0') || (model.category !== 'sys_school_life' && model.type != '0'),
  },
  {
    label: '发布人',
    field: 'publisher',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入发布人!'},
          ];
     },
  },
  {
    label: '发布时间',
    field: 'publishTime',
    component: 'DatePicker',
    componentProps: {
       showTime: true,
       valueFormat: 'YYYY-MM-DD HH:mm:ss'
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入发布时间!'},
          ];
     },
  },
  {
    label: '封面图',
   field: 'coverImage',
   component: 'JImageUpload',
    helpMessage: '建议尺寸：230px*202px',
   componentProps:{
      fileMax: 1
    },
    show: ({ model }) => {
      if (model.category == 'sys_school_major' && model.type == '2'||model.category == 'sys_image_type') {
        return false;
      }
      return (model.category != 'sys_party' && model.type != '0') || 
             (model.category !== 'sys_school_life' && model.type != '0') || 
             (model.category == 'sys_school_major' && model.type == '1');
    }
   
  },
  {
    label: '轮播图',
   field: 'imagefiles',
   component: 'JImageUpload',
   helpMessage: '最多上传10张图片，建议尺寸：514px*409px',
   componentProps:{
      fileMax: 10
    },
    // 使用v-if指令和model属性来动态显示字段
    show: ({ model }) => (model.category == 'sys_image_type')||(model.category=='sys_school_major'),
  },
  {
    field: 'files',
    component: 'JUpload',
    helpMessage: '最多上传10个文件',
    label: '附件上传',
    componentProps: { maxCount: 10 },
    show: ({ model }) => (model.category != 'sys_image_type'), 
  },
   
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];
//子表单数据
//子表表格配置
export const webWorkFileColumns: JVxeColumn[] = [
    {
      title: '创建人',
      key: 'createBy',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '创建日期',
      key: 'createTime',
      type: JVxeTypes.datetime,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '文件名',
      key: 'fileName',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '文件大小',
      key: 'fileSize',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '文件类型',
      key: 'fileType',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '下载次数',
      key: 'orderNum',
      type: JVxeTypes.inputNumber,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '主题类型',
      key: 'themeType',
      type: JVxeTypes.select,
      options:[],
      dictCode:"",
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '文件路径',
      key: 'filePath',
      type: JVxeTypes.file,
      token:true,
      responseName:"message",
      width:"200px",
      placeholder: '请选择文件',
      defaultValue:'',
    },
  ]

// 高级查询数据
export const superQuerySchema = {
  type: {title: '信息分类',order: 0,view: 'list', type: 'string',dictCode: 'web_school_message',},
  titile: {title: '标题',order: 1,view: 'text', type: 'string',},
  summary: {title: '摘要',order: 2,view: 'textarea', type: 'string',},
  priority: {title: '是否推荐',order: 4,view: 'list', type: 'string',dictCode: 'priority_type',},
  publishStatus: {title: '发布状态',order: 5,view: 'list', type: 'string',dictCode: 'web_publish_status',},
  publisher: {title: '发布人',order: 6,view: 'text', type: 'string',},
  publishTime: {title: '发布时间',order: 7,view: 'datetime', type: 'string',},
  coverImage: {title: '封面图',order: 8,view: 'text', type: 'string',},
  //子表高级查询
  webWorkFile: {
    title: '附件表',
    view: 'table',
    fields: {
        createBy: {title: '创建人',order: 0,view: 'text', type: 'string',},
        createTime: {title: '创建日期',order: 1,view: 'datetime', type: 'string',},
        fileName: {title: '文件名',order: 2,view: 'text', type: 'string',},
        fileSize: {title: '文件大小',order: 3,view: 'text', type: 'string',},
        fileType: {title: '文件类型',order: 4,view: 'text', type: 'string',},
        orderNum: {title: '下载次数',order: 5,view: 'number', type: 'number',},
        themeType: {title: '主题类型',order: 6,view: 'list', type: 'string',},
        filePath: {title: '文件路径',order: 7,view: 'file', type: 'string',},
    }
  },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
